package com.ww.yaodao.controller;

import com.ww.yaodao.model.bo.ImportProductDO;
import com.ww.yaodao.model.vo.imports.ImportRespVO;
import com.ww.yaodao.model.vo.imports.ImportVO;
import com.ww.yaodao.service.FileUploadService;
import com.ww.yaodao.service.ImportProductService;
import com.ww.yaodao.util.BaseResult;
import com.ww.yaodao.util.ResultEnums;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 进货模块
 */
@RestController
@RequestMapping("import")
@Api(tags = "采购模块")
@Slf4j
public class ImportProductController {
    @Autowired
    private ImportProductService importProductService;
    @PostMapping("importProductList")
    @ApiOperation(value = "查询所有采购信息")
    public ImportRespVO importProductList(@RequestBody ImportVO importVO){
        log.info("进入查询采购信息页面.....");
        return importProductService.queryImportProduct(importVO);
    }

    /**
     * excel文件导入进数据库中
     *
     * @param file
     * @return
     */
    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("excelImport")
    @ApiOperation(value = "excel批量添加药品")
    @ApiResponses({
            @ApiResponse(code = 2000, message = "添加成功"),
            @ApiResponse(code = 1001, message = "添加失败")
    })
    public ImportRespVO excelImport( @RequestParam("file") @ApiParam(value = "excel文件") MultipartFile file
            ,@RequestPart("dataList") ImportVO importVO ) throws Exception {
        log.info("进入批量导入....");
        return  fileUploadService.upload(file,importVO) ;
    }

    /**
     * 添加单个采购订单+药品
     */
    @PostMapping("addproduct")
    @ApiOperation(value = "添加采购信息")
    @ApiResponses({
            @ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 1000, message = "添加失败")
    })
    public ImportRespVO add(@RequestBody ImportVO importVO) {
        log.info("进入单个添加药品界面");
        return importProductService.insertProduct(importVO);
    }
    /**
     * 修改采购订单
     */
    @PostMapping("updateImport")
    @ApiOperation(value = "修改采购订单")
    @ApiResponses({
            @ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 1000, message = "添加失败")
    })
    public ImportRespVO updateImport(@RequestBody ImportVO importVO) {
        log.info("进入修改采购订单界面");
        return importProductService.updateImport(importVO);
    }

}
